package org.example.coupon.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.example.core.utils.PageUtils;
import org.example.core.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.example.coupon.entity.HomeAdvertiseEntity;
import org.example.coupon.service.HomeAdvertiseService;



/**
 * @author xiaojie_cc
 * @version 1.0
 */
@RestController
@RequestMapping("/sms/backend/advertise")
public class HomeAdvertiseController {
    @Autowired
    private HomeAdvertiseService homeAdvertiseService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R<?> list(@RequestParam(defaultValue = "1") Integer pageNum
            ,@RequestParam(defaultValue = "10") Integer pageSize
            ,@RequestParam(required = false) String name
            ,@RequestParam(required = false) Integer status){
        PageUtils pageUtils = homeAdvertiseService.getHomeAdvertiseList(pageNum, pageSize, name, status);
        return R.ok(pageUtils);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R<?> info(@PathVariable("id") Long id){
        HomeAdvertiseEntity homeAdvertise = homeAdvertiseService.getHomeAdvertiseInfo(id);
        return R.ok(homeAdvertise);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R<?> save(@RequestBody HomeAdvertiseEntity homeAdvertise){
        return homeAdvertiseService.saveHomeAdvertise(homeAdvertise)>0? R.ok():R.error();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R<?> update(@RequestBody HomeAdvertiseEntity homeAdvertise){
        return homeAdvertiseService.updateAdvertiseInfo(homeAdvertise)>0? R.ok():R.error();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R<?> delete(@RequestBody List<Long> ids){
        return homeAdvertiseService.deletes(ids);
    }

}
